<template>
	<view>
		<view class="head">
			<text>{{ tuiqian.customer_name }}</text>
			<view class="txt">{{ tuiqian.address }}</view>
			<view class="bot"></view>
		</view>

		<view class="but">
			<view class="butLeft" @click="tui">
				应退:
				<text>¥{{name}}</text>
				<image src="../../static/spe/01.png" mode="" ></image>
			</view>
			<button type="primary" @click="fahuo">去发货</button>
		</view>
		<view class="" v-for="item in att">
			<view class="shop">
				<image :src="item.cover" mode=""></image>
				<view class="box">
					<view class="boxTop">{{ item.goods_no }}({{ item.title }}）</view>
					<view class="boxLeft">
						数量：{{ liang(item) }}
						<text></text>
					</view>
				</view>
			</view>
			<view class="size">
				<view class="sizeTop" v-for="child in item.product_list">
					<view class="sizeLeft">{{ child.spec_data[0] + '/' + child.spec_data[1] }}（¥{{ child.sell_price }}）</view>
					<view class="sizeRight">X{{ child.number }}</view>
				</view>
			</view>
		</view>
		<!-- 添加新规格弹窗 -->
		<uni-popup ref="popup" type="center">
			<view class="addContent">
				<view class="box">
					<view class="tit tCenter f36 c333">价格</view>
					<view class="input-box"><input type="text" placeholder="最多输入12个字符" v-model="name" /></view>
					<view class="btn f30 tCenter">
						<view class="dropBtn" @click="close">取消</view>
						<view class="submit" @click="open">确定</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			name: '',
			att: '',
			any: [],
			ady: [],
			tuiqian: {},
			add: {},
			
		};
	},
	onLoad() {
	
		this.any = uni.getStorageSync('qiana');
		this.att = uni.getStorageSync('qiana');
		this.tuiqian = uni.getStorageSync('tuiqian');

		console.log(this.any);
		let c=[]
		this.any.forEach(item=>{
			item.product_list.forEach(item=>{
			c.push(item)
			})
		})
		// console.log(c);
		let d=[]
			
	d=c.filter(item=>{
		return	item.number>0
		})
		// console.log(d);
			
		d.forEach(item=>{
		   item.operate_num=item.number
			delete item.spec_data;
			delete item.owe_num;
			delete item.trade_sum;
			delete item.sale_num;
			delete item.unit_id;
			delete item.unit_name;
			delete item.convert_num;
			delete item.store_num;
			delete item.remark;
			delete item.goods_id;
			delete item.discount_price;
			delete item.number;
		})
		// console.log(d);
		this.add=d
		this.hetui()
	},

	methods: {
		tui(){
			// console.log(123);
			this.$refs.popup.open();
		},
		open() {
			// this.$refs.popup.open();
			this.$refs.popup.close();
		},
		close() {
			this.$refs.popup.close();
		},

		chan() {
			this.$refs.popup.open();
		},
		hetui() {
			console.log(this.add);
			let c = 0;
		this.add.forEach(item=>{
		c=c+(+item.operate_num)*item.sell_price
		})
		this.name=c
		// console.log(this.name);
		},
		liang(e) {
			// console.log(e);
			let c = 0;
			e.product_list.forEach(item => {
				c = +item.number + c;
			});
			return c;
		},
		fahuo() {
			this.$ajax('api/v1.order/add', {
				address:'',
				is_payment: 0,
				original_order_id: this.tuiqian.order_id,
				is_delive: 0,
				customer_id: this.tuiqian.customer_id,
				payable: this.name,
				order_type: 3,
				product_list: JSON.stringify(this.add)
			})
				.then(res => {
					// console.log(res);
				uni.switchTab({
					url:'../shop/indent'
				})
				})
				.catch(res => {
					console.log(Error);
				});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f7f4f8;
}
.head {
	height: 173rpx;
	box-sizing: border-box;
	background-color: #ffffff;
	margin-top: 30rpx;
	padding-top: 30rpx;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
	position: relative;
	text {
		margin: 20px 30rpx;
	}
	.txt {
		margin: 40rpx 30rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
		margin-top: 33rpx;
	}
	.bot {
		position: absolute;
		bottom: 0;
		height: 7rpx;
		width: 100%;
		background: url(../../static/client/xian.png) no-repeat center;
		background-size: 100% 100%;
	}
}
.shop {
	height: 204rpx;
	margin-top: 20rpx;
	padding: 35rpx;
	box-sizing: border-box;
	background-color: #ffffff;
	display: flex;
	border-bottom: 2rpx solid #eeeeee;

	image {
		width: 130rpx;
		height: 130rpx;
	}
	.boxTop {
		margin-left: 40rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
	}
	.boxLeft {
		margin-left: 40rpx;
		margin-top: 52rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
		text {
			color: #f64444;
		}
	}
}
.size {
	// height: 166rpx;
	padding: 33rpx;
	box-sizing: border-box;
	background-color: #ffffff;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(102, 102, 102, 1);
	.sizeTop {
		display: flex;
		justify-content: space-between;
	}
}
.tui {
	margin-top: 20rpx;
	height: 110rpx;
	background-color: #ffffff;
	padding: 41rpx 33rpx;
	box-sizing: border-box;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
	display: flex;
	justify-content: space-between;
	image {
		width: 18rpx;
		height: 33rpx;
	}
}
.but {
	width: 100%;
	height: 110rpx;
	position: fixed;
	bottom: 0;
	background-color: #ffffff;
	display: flex;
	box-sizing: border-box;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	line-height: 110rpx;
	padding-left: 29rpx;
	.butLeft {
		width: 495rpx;
		background-color: #ffffff;
		display: flex;
		image {
			width: 44rpx;
			height: 44rpx;
			position: relative;
			top: 33rpx;
			left: 20rpx;
		}
		text {
			color: #f64444;
		}
	}
	button {
		line-height: 110rpx;
		flex: 1;
		font-size: 30rpx;
	}
}
</style>
